package auto.setting;

import auto.device.Phione;
import io.appium.java_client.AppiumBy;
import io.appium.java_client.AppiumDriver;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

//这个类里面只有日间夜间切换检测的方法
public class DayNightSwitching {

    //入间夜间切换检测的方法
    public String dayNightDetection(){
        Phione phione = new Phione();
        AppiumDriver driver = phione.driver;
        WebDriverWait wait = phione.wait;

        System.out.println("切换页面的过程中请观察页面是否变更");

        //循环两边，都是点击底部导航栏
        int i=1;

        while(i<=2){
            //首先点击设置页面
            wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.iOSClassChain("**/XCUIElementTypeButton[`name == \"设置\"`]"))).click();

            //查看切换日间夜间的按钮是不是消失了
            try{
                wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("appearance"))).click();

            }catch(TimeoutException e){
                System.out.println("切换日间夜间模式按钮消失");
                return "切换日间夜间模式按钮消失";
            }

            //点击联系人
            wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("联系人"))).click();

            //点击聊天列表页面
            wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.accessibilityId("聊天"))).click();

            i++;
        }

        System.out.println("日间夜间切换成功");
        driver.quit();
        return "日间夜间切换成功";
    }
}
